/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.ad.consumer;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author sexta13
 * @author ricardo
 */
public class FeedReader implements ServletContextListener {

	private ScheduledExecutorService executor;
    private SchedulerManager service;
	
	public void contextInitialized(ServletContextEvent sce) {
		service = new SchedulerManager();
        // setup single thread to run background service every 5 minutes
        executor = Executors.newSingleThreadScheduledExecutor();
        executor.scheduleAtFixedRate((Runnable) service, 0, 15, TimeUnit.MINUTES);
        // make the background service available to the servlet context
        sce.getServletContext().setAttribute("service", service);
    }

    public void contextDestroyed(ServletContextEvent sce) {
        executor.shutdown();
    }
    
}
